package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.WmNewsMessageConstants;
import com.heima.model.search.vos.SearchArticleVo;
import com.heima.search.service.ArticleSearchService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听同步ES的类
 */
@Component
public class SyncArticleListener {

    @Resource
    private ArticleSearchService searchService;
    /**
     * 监听同步ES的方法
     * @param message
     */
    @KafkaListener(topics = WmNewsMessageConstants.ARTICLE_ES_SYNC_TOPIC)
    public void getMessage(String message){
        //1.转化类型
        SearchArticleVo searchArticleVo = JSON.parseObject(message, SearchArticleVo.class);

        //2.新增数据到Es中
        searchService.addArticleToEs(searchArticleVo);
    }
}